# -*- coding: utf8 -*-

from typing import Dict, Iterable, List, Tuple, Union, Any


class DataColumn:
    r''' 数据库中的一列。
    '''
    __slots__ = ('col_name', 'col_type', 'col_size', 'col_scale', 'col_comment', 'col_nullable', 'col_default', 'col_unique',
                 'col_check', 'col_primary_key', 'col_foreign_key', 'col_cascade', 'col_index',)

    def __init__(
        self,
        col_name: str,
        col_type: str,
        col_size: int,
        col_scale: int,
        col_comment: str,
        col_nullable: bool,
        col_default: str,
        col_unique: str,
        col_check: str,
        col_primary_key: bool,
        col_foreign_key: str,
        col_index: str
    ):
        r''' 构造列。

        :param col_name: 列名。
        :param col_type: 列类型。
        :param col_size: 列长度，某些类型的列是固定长度，该参数无效。
        :param col_scale: 数值缩放倍数，即小数位长度，对于非数值类型和整数无效。
        :param col_comment: 列说明。
        :param col_nullable: 列值是否可以为空。
        :param col_default: 列值的默认值。
        :param col_unique: 列值是否唯一。
        :param col_check: 列的检查条件。
        :param col_primary_key: 该列是否主键列。
        :param col_foreign_key: 该列对应的外键。
        '''
        self.col_name = col_name
        self.col_type = col_type
        self.col_size = col_size
        self.col_scale = col_scale
        self.col_comment = col_comment
        self.col_nullable = col_nullable
        self.col_default = col_default
        self.col_unique = col_unique
        self.col_check = col_check
        self.col_primary_key = col_primary_key
        self.col_foreign_key = col_foreign_key
        self.col_index = col_index

    def __repr__(
        self
    ) -> str:
        return 'DataColumn(col_name={!r:},col_type={!r:},col_size={!r:},col_scale={!r:},col_comment={!r:},col_nullable={!r:},col_default={!r:},col_unique={!r:},col_check={!r:},col_primary_key={!r:},col_foreign_key={!r:},col_index={!r:}'.format(
            self.col_name, self.col_type, self.col_size, self.col_scale, self.col_comment, self.col_nullable, self.col_default,
            self.col_unique, self.col_check, self.col_primary_key, self.col_foreign_key, self.col_index)

    def __str__(
        self
    ) -> str:
        return repr(self)


class DataTable:
    r''' 数据库中的一个表。
    '''

    def __init__(
        self,
        name: str,
        comment: str,
        cols: Iterable[DataColumn]
    ):
        self.name = name
        self.comment = comment
        self.cols = tuple(cols)

    def __repr__(
        self
    ) -> str:
        return 'DataTable(name={!r:},comment={!r:},cols={!r:}'.format(self.name, self.comment, self.cols)

    def __str__(
        self
    ) -> str:
        return repr(self)
